<template>
	<view>
		<navbar title="全部评价"></navbar>
		<view class="evaluate-stat fa jcsb">
			<view class="left fa">
				<view class="rate">{{all}}</view>
				<view>
					<view class="name">评分</view>
					<uni-rate :size="12" active-color="#FE3134" v-model="all" :readonly="true"/>
				</view>
			</view>
			<view class="right fa">
				<view class="right-list fa fdc">
					<view>好评</view>
					<view class="num">{{good}}</view>
				</view>
				<view class="right-list fa fdc">
					<view>中评</view>
					<view class="num">{{medium}}</view>
				</view>
				<view class="right-list fa fdc">
					<view>差评</view>
					<view class="num">{{bed}}</view>
				</view>
			</view>
		</view>
		<view class="evaluate-top bgf">
			<view class="type-box flex fww">
				<view class="type-list" :class="{active: typeIndex == index}" v-for="(item, index) in typeList" :key="index" @click="typeChange(index)">{{item}}</view>
			</view>
		</view>
		<view class="evaluate-box">
			<view class="evaluate-list bgf" v-for="(item, index) in list" :key="index">
				<view class="user-box fa jcsb">
					<view class="fa">
						<image class="avatar" :src="item.account.avatar" mode=""></image>
						<view class="nickname">{{item.account.name}}</view>
						<uni-rate :size="12" active-color="#FE3134" v-model="item.distribution" :readonly="true"/>
					</view>
					<view class="time">{{item.createTime}}</view>
				</view>
				<view class="content">{{item.content}}</view>
				<view class="img-box flex fww" v-if="item.image.length > 0">
					<image :src="row" mode="" v-for="(row, col) in item.image" :key="col" @click="utils.previewImage(item.image, col)"></image>
				</view>
			</view>
		</view>
		<view class="noorder-box fa fdc" v-if="nodata">
			<image class="noorder-image" src="../../static/noorder.png" mode=""></image>
			<view class="prompt">暂无评价</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: 0,
				typeList: ['全部评论', '好评(0)', '中评(0)', '差评(0)'],
				typeIndex: 0,
				page: 1,
				count: 0,
				list: [],
				all: 0,
				good: 0,
				medium: 0,
				bed: 0,
				nodata: 0
			};
		},
		onLoad(options) {
			this.getCount()
			this.getList()
		},
		onReachBottom() {
			if(this.list.length < this.count) {
				this.page++
				let t = ''
				if(this.typeIndex > 0) {
					t = index - 1
				}
				this.getList(t)
			}
		},
		methods: {
			getCount() {
				this.api.commentCountFunc().then(res => {
					if(res.code == 200) {
						this.all = res.data.all
						this.good = res.data.good
						this.medium = res.data.medium
						this.bed = res.data.bed
						this.typeList.splice(1, 1, ('好评(' + res.data.good + ')'),)
						this.typeList.splice(2, 1, ('中评(' + res.data.medium + ')'))
						this.typeList.splice(3, 1, ('差评(' + res.data.bed + ')'))
					}
				})
			},
			typeChange(index) {
				this.typeIndex = index
				let t = ''
				if(index > 0) {
					t = index - 1
				}
				this.getList(t)
			},
			getList(t = '') {
				this.api.commentListFunc({
					t: t
				}).then(res => {
					if(res.code == 200) {
						this.count = res.total
						this.list = this.page == 1 ? res.rows : this.list.concat(res.rows)
						this.nodata = this.list.length > 0 ? 0 : 1
						this.list.forEach(item => {
							if(item.image) {
								item.image = item.image.split(',')
							}
						})
					}
				})
			},
		}
	}
</script>
<style>
	page{
		padding-bottom: env(safe-area-inset-bottom);
		background-color: #fff;
	}
</style>
<style lang="scss" scoped>
	.evaluate-stat{
		margin: 0 28rpx;
		padding: 24rpx 0;
		border-bottom: 1rpx solid #E6E6E6;
		font-size: 26rpx;
		font-weight: bold;
		.left{
			padding-right: 40rpx;
			.rate{
				margin-right: 28rpx;
				font-size: 78rpx;
				color: #18C954;
				line-height: 92rpx;
			}
			.name{
				margin-bottom: 20rpx;
			}
		}
		.right{
			position: relative;
			padding-left: 48rpx;
			padding-right: 20rpx;
			&::after{
				content: '';
				position: absolute;
				top: 50%;
				left: 0;
				transform: translateY(-50%);
				width: 2rpx;
				height: 110rpx;
				background-color: #E6E6E6;
			}
			.right-list{
				margin-right: 74rpx;
				&:last-child{
					margin-right: 0;
				}
			}
		}
	}
	.evaluate-top{
		padding: 10rpx 20rpx 2rpx;
		.type-box{
			.type-list{
				margin-top: 20rpx;
				margin-right: 20rpx;
				padding: 0 16rpx;
				height: 40rpx;
				line-height: 40rpx;
				border-radius: 8rpx;
				text-align: center;
				font-size: 24rpx;
				background: #ededed;
				&.active{
					color: #fff;
					background: var(--theme);
				}
			}
		}
	}
	.evaluate-box{
		margin-top: 16rpx;
		padding-bottom: 2rpx;
		.evaluate-list{
			margin-bottom: 16rpx;
			padding: 30rpx 20rpx;
			.user-box{
				.avatar{
					margin-right: 16rpx;
					width: 64rpx;
					height: 64rpx;
					border-radius: 50%;
				}
				.nickname{
					margin-right: 16rpx;
				}
			}
			.content{
				margin-top: 20rpx;
			}
			.img-box{
				image{
					margin-top: 19rpx;
					margin-right: 19rpx;
					width: 224rpx;
					height: 224rpx;
					border-radius: 8rpx;
					&:nth-child(3n){
						margin-right: 0;
					}
				}
			}
		}
	}
	.noorder-box{
		margin-top: 206rpx;
		.noorder-image{
			width: 464rpx;
			height: 253rpx;
		}
		.prompt{
			font-size: 22rpx;
			color: #777;
		}
	}
</style>
